package example.demo.nospring;

import example.demo.nospring.entity.User;
import example.demo.nospring.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

@Slf4j
public class MybatisUse {
    public static void main(String[] args) throws Exception {
        InputStream resource = Resources.getResourceAsStream("mybatis-nospring/mybatis.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //org.apache.ibatis.binding.MapperProxy@1d16f93d
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);

//        User user = mapper.selectOneById(4);//
//        log.info(user.toString());
        List<User> jjjj = mapper.selectOneByIdPage("jjjj", 0, 10, true);
        jjjj.forEach(System.out::println);
//        User u = new User();
//        u.setId(999);
//        u.setRealName("Wahah");
//        int i = mapper.insertOne(u);
//        System.out.println(i);
//        sqlSession.commit();
        sqlSession.close();


    }
}
